// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import VueRouter from 'vue-router';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';
import Vuex from 'vuex';
import store from './store';

Vue.use(VueRouter);
Vue.use(ElementUI);
Vue.use(Vuex);
//用vue绑定到原型上，全局使用axios
Vue.prototype.axios = axios;

Vue.config.productionTip = false

//路由跳转之前
router.beforeEach((to,from,next) => {
    let isLogin = sessionStorage.getItem('isLogin');
    console.log(isLogin)
    if(to.path != '/landing' && to.path != '/login'){
      if(isLogin == null){
        // 未登录
        next({path:'/landing'});
      }else{
        // 已登录
        console.log("已登录")
        // 注销
        if(to.path == '/logout'){
            //清空
            sessionStorage.clear();
            //跳转到登录页面
            next({path:'/landing'});
        }
        next();
      }
    }else{
      next();
    }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
